package website.haicheng.system;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
import website.haicheng.core.config.IdService;


@RestController
@EnableSwagger2WebMvc
@EnableDiscoveryClient
@MapperScan(basePackages = "website.haicheng.system.mapper")
@SpringBootApplication(scanBasePackages = {"website.haicheng.core", "website.haicheng.system"})
public class CloudSystemApplication {

    @Autowired
    private IdService idService;

    public static void main(String[] args) {
        SpringApplication.run(CloudSystemApplication.class, args);
    }

    @Bean()
    public Docket defaultApi2() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("Cloud-Sys")
                        .description("sys服务接口文档")
                        .termsOfServiceUrl("https://www.baidu.com/")
                        .contact(new Contact("龙海成", "https://www.baidu.com/", "582895699@qq.com"))
                        .version("1.0")
                        .build())
                //分组名称
                .groupName("1.0")
                .select()
                //这里指定Controller扫描包路径
                .apis(RequestHandlerSelectors.basePackage("website.haicheng.system.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    @GetMapping(value = "/get")
    public void get() {
        for (int i = 0; i < 100; i++) {
            System.out.println(idService.nextId());
        }
    }
}
